<template>
  <div class="search">
    <!-- 搜索页头部 -->
    <div class="type">
      <span class="iconfont" @click="goto()">&#xe779;</span>
      搜索
    </div>
    <!-- 输入框 -->
    <div class="inp">
      <span class="iconfont">&#xe86e;</span>
      <input type="text" v-model="value" name="" id="" />
      <button @click="get">搜索</button>
    </div>
    <!-- 历史记录 -->
    <div class="lishi">
      <div>
        <p>历史记录</p>
        <span @click="cls()" class="iconfont">&#xe6a0;</span>
      </div>
      <ul>
        <li v-for="item in data">
          <router-link :to="{ path: '/home/type', query: { name: item } }">{{
            item
          }}</router-link>
        </li>
      </ul>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.search {
  overflow: hidden;
  .type {
    text-align: center;
    line-height: 50px;
    font-size: 16px;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 9999;
    border-bottom: 1px solid #ccc;
    font-weight: bold;
    color: rgb(116, 116, 116);
    text-align: center;
    background-color: white;
    span {
      position: absolute;
      display: block;
      height: 50px;
      width: 40px;
    }
  }
  .inp {
    margin-top: 50px;
    position: relative;
    height: 40px;
    display: flex;
    padding: 2%;
    span {
      position: absolute;
      top: 20px;
      font-size: 20px;
      left: 20px;
    }
    input {
      border: none;
      padding-left: 40px;
      box-sizing: border-box;
      background-color: rgb(226, 226, 226);
      border-radius: 10px;
      line-height: 30px;
      width: 70%;
      margin-top: 5px;
      font-size: 18px;
      color: rgb(104, 104, 104);
      outline-style: none;
    }
    button {
      display: block;
      background-color: red;
      border-radius: 10px;
      border: none;
      margin-top: 5px;
      height: 35px;
      color: white;
      font-size: 18px;
      margin-left: 3%;
      width: 25%;
    }
  }
  .lishi {
    padding: 2%;
    div {
      position: relative;
      p {
        font-size: 16px;
        padding: 8px;
        border-radius: 5px;
        text-align: center;
        width: 80px;
        background-color: rgb(224, 224, 224);
        color: rgb(44, 44, 44);
      }
      span {
        position: absolute;
        right: 30px;
        top: 5px;
        font-weight: bold;
        font-size: 22px;
      }
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      margin-top: 10px;
      margin-left: -5px;
    }
    li {
      a {
        display: block;
        padding: 10px;
        margin: 5px;
        background-color: rgb(221, 221, 221);
        color: rgb(104, 104, 104);
        font-size: 14px;
        border-radius: 5px;
      }
    }
  }
}
</style>
<script>
export default {
  name: "search",
  data() {
    return {
      value: "",
      // 历史记录存储
      data: [],
    };
  },
  methods: {
    goto() {
      this.$router.go(-1);
    },
    cls() {
      this.data = [];
    },
    // 搜索跳转
    get() {
      if (this.value.length == 0) {
        alert("请输入内容");
      } else {
        this.data.push(this.value);
        let myname = this.value;
        this.value = "";
        this.$router.push({ path: "/home/type", query: { name: myname } });
      }
    },
  },
};
</script>